package com.cnap.multiclouldmgmt.controller;

import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cnap.multiclouldmgmt.model.CommonResult;
import com.cnap.multiclouldmgmt.model.vm.DelNodeImageClusterInfoModel;
import com.cnap.multiclouldmgmt.model.vm.DelNodeImageModel;
import com.cnap.multiclouldmgmt.model.vm.DelSvcToVmModel;
import com.cnap.multiclouldmgmt.model.vm.VmCreateModel;
import com.cnap.multiclouldmgmt.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.CachedIntrospectionResults;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 对接虚拟机的相关系统
 * @author dyq
 */
@Api(tags ="对接虚拟机相关系统")
@RequestMapping(path = "/cnap/multicloudmgmt/v1/vm")
@RestController
@ResponseBody
public class VmController {

    private final static Logger LOGGER = LoggerFactory.getLogger(VmController.class);

    @Autowired
    private VmResourceService vmResourceService;

    @Autowired
    private DockerHarborService dockerHarborService;

    @Autowired
    private MicroSvcInfoService microSvcInfoService;

    @Autowired
    private CacheService cacheService;

    /**
     * 开通云资源，完成以下内容
     * 1.申请开通虚机，调用其他接口
     * 2.完成安全组开通，
     * 3.完成k8s等组件安装
     * 4、完成调度平台组件安装
     * 如果svcId已经存在了，且errorMsg不为空，那就重试
     * 整个流程顺序执行，除非遇到问题会停下
     * @param vmCreateModel 基本信息
     * @return 结果
     */
    @ApiOperation(value = "5-1 创建服务需要的虚拟机资源",httpMethod = "POST",
            notes = "")
    @RequestMapping(path = "/createVmResource",method = RequestMethod.POST)
    public CommonResult<Void> createVmResource(@RequestBody VmCreateModel vmCreateModel) {

        try {

            vmResourceService.createVmResource(vmCreateModel);
            return CommonResult.successMsg("createVmResource succees");

        }catch (Exception e){

            LOGGER.error("VmController createVmResource error",e);

            return CommonResult.failed(e.getMessage());
        }
    }

}
